package dead.queue.mt.demo.service;

import dead.queue.mt.demo.entity.MessageInfo;
import dead.queue.mt.demo.entity.MessageNameConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.UUID;

@Service
@Slf4j
public class MessageImpl implements IMessage {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @Override
    public String test1() {
        MessageInfo info = new MessageInfo();
        //消息id
        info.setMsgId(String.valueOf(UUID.randomUUID()));
        //消息内容
        info.setMsg("手动挡死信测试消息");
        //发送时间
        info.setTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        //发送消息
        rabbitTemplate.convertAndSend(MessageNameConfig.testExchangeName, MessageNameConfig.testRoutingKey, info);
        System.out.println("消息发送完毕");
        return "消息发送完毕";
    }
}
